<?php

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
 * 控制器创建: php artisan make:controller Admin/ConfigController
 */
class ConfigController extends CommonController
{
    /**
     * 系统设置信息
     */
    public function index()
    {
        //配置信息
        $list =  DB::table("config")->select('name','value')->get()->toArray();
        $info = array();
        foreach ($list as $key => $value) {
            $info[$value->name] = $value->value;
        }
        $info = json_encode($info,true);
        return view('admin/config/index')->with('system',$info);
    }

    /**
     * 编辑系统设置信息
     */
    public function edit(Request $request)
    {
        if($request->isMethod('post')){
            $data = $request->post();
            foreach ($data as $k=>$v){
                DB::table('config')->where(['name'=>$k])->update(['value'=>$v]);
            }
            return response()->json(['code' => 1, 'msg' => '保存成功!']);
        }
    }

}
